# -*- coding: utf8 -*-

import os
import sys
reload(sys) 
sys.setdefaultencoding('utf8')
import caller
import webkit
import webpage
import webelement
import time

gconfig = caller.GlobalConfig()
gconfig.init("10.58.222.103:2181")

wk = webkit.WebKit("test")
url = "http://www.qyer.com"
print "Get : " + url
wk.setFilterRules(["*"])
page = wk.getWebPage(url, 100, 30000)
if page != None:
    print "Get success. " + page.getTitle()
    cookies = page.getCookies()
    jar = webpage.CookieJar(cookies) 

    jarjson = jar.toJson()
    print jarjson
    
    njar = webpage.CookieJar()
    njar.loadFromJson(jarjson)
    print njar.toJson()

    #for c in cookies:
        #print c.toJson()
    #buf = page.webPageImageBuffer()
    #try:
        #fp = open("qy.png",'w')
        #fp.write(buf)
    #except:
        #print "file error."
    page.destroy()
    
wk.release()
